import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.List;

public class RedisDemoList {

    public static void test1(Jedis jedis) {
        System.out.println("lpush   lrange");
        jedis.flushDB();

        jedis.lpush("key","111","222","333");

        List<String> result = jedis.lrange("key", 0, -1);
        System.out.println("result = " + result);
    }

    public static void test2 (Jedis jedis) {
        System.out.println("lpop");
        jedis.flushDB();

        jedis.rpush("key","111","222","333");

        List<String> result1 = jedis.lrange("key", 0, -1);
        System.out.println("result1 = " + result1);

        jedis.lpop("key");

        List<String> result = jedis.lrange("key",0, -1);
        System.out.println("result = " + result);
    }

    public static void test3(Jedis jedis) {
        System.out.println("blpop");
        jedis.flushDB();

        List<String> result = jedis.blpop(10,"key");
        System.out.println("result = " + result);
        System.out.println("result[0] : " + result.get(0));
        System.out.println("result[1] : " + result.get(1));
    }

    private static void test4(Jedis jedis) {
        System.out.println("llen");
        jedis.flushDB();

        jedis.lpush("key","111","222","333");
        long len = jedis.llen("key");
        System.out.println("len = " + len);

    }

    public static void main(String[] args) {
        JedisPool jedisPool = new JedisPool("tcp://127.0.0.1:8888");
        try (Jedis jedis = jedisPool.getResource()) {
//            test1(jedis);
//            test2(jedis);
//            test3(jedis);
            test4(jedis);
        }
    }


}
